package com.gnerv.author.config;

import com.alibaba.fastjson.JSON;
import com.gnerv.author.entity.R;
import org.apache.shiro.web.filter.authc.UserFilter;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.IOException;

/**
 * @description: shiro未登录跳转拦截
 * @author: Gnerv LiGen
 * @date: 2018-05-18
 **/
public class ShiroFilter extends UserFilter {

    @Override
    protected void redirectToLogin(ServletRequest request, ServletResponse response) throws IOException {
        response.setContentType("application/json; charset=utf-8");
        response.getWriter().print(JSON.toJSON(R.back(401, "请登录")));
    }

}